package genetic.q1.functions.sumlist.statements;

import genetic.q1.WithallPhenotype;
import genetic.q1.functions.Program;
import genetic.q1.functions.ProgramObject;
import genetic.q1.functions.Statement;
import genetic.q1.functions.Variable;

public class Subtract extends Statement {

	private Subtract(ProgramObject[] evals) {
		super("Subtract", evals);
	}

	public Subtract() {
		super("Subtract", null);
	}

	@Override
	public Statement CreateInstance(ProgramObject[] evals) {
		return new Subtract(evals);
	}

	@Override
	public ProgramObject choose(int j, int i, WithallPhenotype withallPhenotype) {
		if (j==0){
			return withallPhenotype.getFromWriteVars(i);
		} else if (j==1){
			return withallPhenotype.getFromReadWriteVars(i);
		} else if (j==2){
			return withallPhenotype.getFromReadWriteVars(i);
		}
		return null;
	}

	@Override
	public int execute(Program program) {
		int var1 = ((Variable)evals[1]).getValue();
		int var2 = ((Variable)evals[2]).getValue();
		((Variable)evals[0]).setValue(var1-var2);
		return program.getCounter() + 1;
	}

	@Override
	public String getObjectName() {
		return "Sub("+evals[0].getObjectName()+","+evals[1].getObjectName()+","+evals[2].getObjectName()+");";
	}

	@Override
	public int getNumVars() {
		return 3;
	}
	

	@Override
	public String toString() {
		return evals[0].toString() + " = " + evals[1].toString() + " - " + evals[2].toString();
	}

}
